package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.OriginalArg;
import com.azier.kapacitor.script.method.ByMeasurement;
import com.azier.kapacitor.script.method.Quiet;
import com.azier.kapacitor.script.node.nodebind.*;
import com.azier.kapacitor.script.node.nodebind.qlnodebind.*;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Group the data by a set of tags.
**/
/**
通过一组标签对数据进行分组。
**/
public class GroupByNode extends AbstractNode implements AlertNodeBind, BarrierNodeBind, BottomNodeBind, ChangeDetectNodeBind, CombineNodeBind, CountNodeBind,
        CumulativeSumNodeBind, DefaultNodeBind, DeleteNodeBind, DerivativeNodeBind, DifferenceNodeBind, DistinctNodeBind, Ec2AutoscaleNodeBind,
        ElapsedNodeBind, EvalNodeBind, FirstNodeBind, FlattenNodeBind, GroupByNodeBind, HoltWintersNodeBind, HoltWintersWithFitNodeBind,
        HttpOutNodeBind, HttpPostNodeBind, InfluxDBOutNodeBind, JoinNodeBind, K8sAutoscaleNodeBind, KapacitorLoopbackNodeBind, LastNodeBind, LogNodeBind,
        MaxNodeBind, MeanNodeBind, MedianNodeBind, MinNodeBind, ModeNodeBind, MovingAverageNodeBind, PercentileNodeBind, SampleNodeBind, ShiftNodeBind,
        SideloadNodeBind, SpreadNodeBind, StateCountNodeBind, StateDurationNodeBind, StatsNodeBind, StddevNodeBind, SumNodeBind, SwarmAutoscaleNodeBind,
        TopNodeBind, UnionNodeBind, WhereNodeBind, WindowNodeBind {
    private static final String name = "groupBy";

    public GroupByNode(Object ...tag) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        for(Object argf : tag){
        this.args.add(new OriginalArg(argf));
        }
    }

    private GroupByNode(String name, String ...dims) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        for(Object argf : dims){
            this.args.add(new OriginalArg(argf));
        }
    }
    /**
    If set will include the measurement name in the group ID. Along with any other group by dimensions.
    **/
    /**
    如果设置，则将测量名称包含在组ID中。连同其他按维度分组。
    **/
    public GroupByNode byMeasurement(){
        ByMeasurement byMeasurement = new ByMeasurement();
        super.addMethod(byMeasurement);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public GroupByNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }

    /**
     * exclude
     */
    public GroupByNode exclude(String ...dims){
        GroupByNode nextNode = new GroupByNode("exclude",dims);
        this.setNextNode(nextNode);
        nextNode.zetHeadNode(this.getHeadNode());
        return nextNode;
    }

}